# coding: utf-8
import redis


class ConfigureFile:

    def __init__(self):
        self.current_environment = 'test'  # line or test line线上环境 test 测试环境
        self.default_configure = {  # 默认线上
            'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': 'automation_db',
                'USER': 'huangshunyao',
                'PASSWORD': '123456',
                'HOST': '223.166.240.56',
                'PORT': 8012,
            }
        }
        self.rabbit_broker, self.redis_broker = 'pyamqp://admin:123456@223.166.240.56//', 'redis://:hsy5332@223.166.240.56:6379/'
        self.redis_host, self.redis_password, self.redis_port = '223.166.240.56', 'hsy5332', 6379

    def get_configure_file(self, configure_name, environment_name):
        if configure_name == 'setting_mysql':
            return self.setting_configure_path(environment_name) if environment_name else self.setting_configure_path(self.current_environment)
        elif configure_name == 'rabbit':
            return self.rabbitmq_configure_fun(environment_name) if environment_name else self.rabbitmq_configure_fun(self.current_environment)
        elif configure_name == 'broker_redis':
            return self.redis_broker_configure(environment_name) if environment_name else self.redis_broker_configure(self.current_environment)
        elif configure_name == 'redis':
            return self.redis_configrue_fun(environment_name) if environment_name else self.redis_configrue_fun(self.current_environment)
        else:
            print('configure_name不存在,请传递正确的configure_name')
            return False

    def setting_configure_path(self, configure_name):
        default_configure = self.default_configure['default']
        if configure_name == 'localhost':
            default_configure['USER'], default_configure['PASSWORD'], default_configure['HOST'], default_configure['PORT'] = 'huangshunyao', '123456', 'localhost', '8012'
        elif configure_name == 'test':
            default_configure['USER'], default_configure['PASSWORD'], default_configure['HOST'], default_configure['PORT'] = 'huangshunyao', '123456', '192.168.1.5', '8012'
        return self.default_configure

    def rabbitmq_configure_fun(self, configure_name):
        if configure_name == 'localhost':
            self.rabbit_broker = 'pyamqp://guest@localhost//'
        elif configure_name == 'test':
            self.rabbit_broker = 'pyamqp://admin:123456@192.168.1.5//'
        return self.rabbit_broker

    def redis_broker_configure(self, configure_name):
        if configure_name == 'localhost':
            self.redis_broker = 'redis://127.0.0.1:6379/'
        elif configure_name == 'test':
            self.redis_broker = 'redis://:hsy5332@192.168.1.5:6379/'
        return self.redis_broker

    def redis_configrue_fun(self, configure_name):
        if configure_name == 'localhost':
            self.redis_host, self.redis_password, self.redis_port = '127.0.0.1', '', 6379
        elif configure_name == 'test':
            self.redis_host, self.redis_password, self.redis_port = '192.168.1.5', 'hsy5332', 6379
        return redis.Redis(connection_pool=redis.ConnectionPool(host=self.redis_host, port=self.redis_port, password=self.redis_password))


if __name__ == "__main__":
    pass
